/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ftpcombiner.listeners;

import ftpcombiner.ApplicationController;
import ftpcombiner.filesystem.FileSystem;
import ftpcombiner.gui.applicationframe.framesplitter.FileTable;
import ftpcombiner.server.virtualfiles.VirtualFile;
import ftpcombiner.server.virtualfiles.VirtualFolder;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

/**
 *
 * @author Ben
 */
public class DeleteListener extends MouseAdapter {

    FileTable parent;

    @Override
    public void mouseReleased(MouseEvent e) {
        //System.out.println("mouseReleased");
        if (parent == null) {
            parent = ApplicationController.getInstance().getApplicationFrame().getFrameSplitter().getFileTable();
        }

        for (int i : parent.getSelectedRows()) {
            //System.out.println("isvitrualfile: " + (parent.getValueAt(i, 0) instanceof VirtualFile));
            if (parent.getValueAt(i, 0) instanceof VirtualFile) {
                FileSystem.getInstance().delete((VirtualFile) parent.getValueAt(i, 0));
            } else {
                FileSystem.getInstance().delete((VirtualFolder) parent.getValueAt(i, 0));
            }
        }
    }
}
